/**
 * This file is part of Wireless TransFer.
 *
 *   Wireless TransFer is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *	
 *   Wireless TransFer is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with Wireless TransFer.  If not, see <http://www.gnu.org/licenses/>.
 *
 *	 Copyright (C) 2011
 *   @author skalman
 */

package com.wirelesstransfer.activity.filebrowser;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

public class FileSize {
		
	// Prefix
	public final static String KB = "KiB";
	public final static String MB = "MiB";
	public final static String GB = "GiB";
	public final static String BYTES = "Bytes";
	
	private static Map<String, String> ret;
	
	public static Map<String, String> getFileSize(File file) {

		long fileSizeRet = file.length();
		
		return getFileSize(fileSizeRet);
	}
	
	public static Map<String, String> getFileSize(Long fileSize) {

		String unitRet = "";
		
		if(fileSize < 1024) {
			unitRet = BYTES;			
		}
		else if(fileSize < 1048576) {
			unitRet = KB;
			fileSize = fileSize / 1024;
		}
		else if(fileSize < 1073741824) {
			unitRet = MB;
			fileSize = fileSize / 1048576;
		}
		else {
			unitRet = GB;
			fileSize = fileSize / 1073741824;
		}
		
		ret = new HashMap<String, String>();
		ret.put("fileSize", String.valueOf(fileSize));
		ret.put("unit", unitRet);
		
		return ret;		
	}

	public static String getUnit(long fileSize) {

		if(fileSize < 1024)
			return BYTES;
		else if(fileSize < 1048576)
			return KB;
		else if(fileSize < 1073741824)
			return MB;
		else
			return GB;
	}

}
